<!DOCTYPE html>
<html lang="en">
<head>
    <meta charset="UTF-8">
    <meta name="viewport" content="width=device-width, initial-scale=1.0">
    <title>Document</title>
</head>
<body>
    <script>
        /**
         * 
         *  1、接⼝权限
         * 
         * 接⼝权限⽬前⼀般采⽤ jwt 的形式来验证，没有通过的话⼀般返回 401 ，跳转到登录⻚⾯重新进⾏登录
            登录完拿到 token ，将 token 存起来，通过 axios 请求拦截器进⾏拦截，每次请求的时候头部携带 token

            axios.interceptors.request.use(config => {
                config.headers['token'] = cookie.get('token')
                    return config
                })
            axios.interceptors.response.use(res=>{},{response}=>{
                if (response.data.code === 40099 || response.data.code === 40098) { //token过期或者错误
                    router.push('/login')
                }
            })


            按钮权限
            菜单权限
                // 通过 addRoutes 动态挂载之间，需要将数据处理⼀下
            路由权限

                import router from './router'
import store from './store'
import { Message } from 'element-ui'
import NProgress from 'nprogress' // progress bar
import 'nprogress/nprogress.css'// progress bar style
import { getToken } from '@/utils/auth' // getToken from cookie
NProgress.configure({ showSpinner: false })// NProgress Configuration
// permission judge function
function hasPermission(roles, permissionRoles) {
 if (roles.indexOf('admin') >= 0) return true // admin permission passed
directly
 if (!permissionRoles) return true
 return roles.some(role => permissionRoles.indexOf(role) >= 0)
}
const whiteList = ['/login', '/authredirect']// no redirect whitelist
router.beforeEach((to, from, next) => {
 NProgress.start() // start progress bar
 if (getToken()) { // determine if there has token
 /* has token*/
//  if (to.path === '/login') {
//  next({ path: '/' })
//  NProgress.done() // if current page is dashboard will not trigger af
// terEach hook, so manually handle it
//  } else {
//  if (store.getters.roles.length === 0) { // 判断当前⽤户是否已拉取完user_
// info信息
//  store.dispatch('GetUserInfo').then(res => { // 拉取user_info
//  const roles = res.data.roles // note: roles must be a array! suc
// h as: ['editor','develop']
//  store.dispatch('GenerateRoutes', { roles }).then(() => { // 根据
// roles权限⽣成可访问的路由表
//  router.addRoutes(store.getters.addRouters) // 动态添加可访问路由
// 表
//  next({ ...to, replace: true }) // hack⽅法 确保addRoutes已完成 ,
// set the replace: true so the navigation will not leave a history record
//  })
//  }).catch((err) => {
//  store.dispatch('FedLogOut').then(() => {
//  Message.error(err || 'Verification failed, please login again'
// )
//  next({ path: '/' })
         * 
         * **/ 
    </script>
</body>
</html>